package dao

import (
	"day1.13/model/mysql"
)

func ArticleAdd(name string, content string) (add mysql.Article, err error) {
	alticle := mysql.Article{

		Name:    name,
		Content: content,
	}
	err = mysql.DB.Model(mysql.Article{}).Create(&alticle).Error
	return alticle, err
}

func ArticleList(atoi int) (list mysql.Article, err error) {
	err = mysql.DB.Where("id=?", atoi).Limit(1).Find(&list).Error
	return list, err
}

func ArticleReview(userId int, articleId int, context string) (review mysql.ArticleReview, err error) {
	review = mysql.ArticleReview{
		UserId:    userId,
		ArticleId: articleId,
		Context:   context,
	}
	err = mysql.DB.Debug().Model(&mysql.ArticleReview{}).Create(&review).Error
	return review, err
}

func ArticleReviews(id int, id2 int, articleId int, context string) (review mysql.ArticleReview, err error) {
	review = mysql.ArticleReview{
		UserId:    id,
		FatherId:  id2,
		ArticleId: articleId,
		Context:   context,
	}
	err = mysql.DB.Debug().Model(&mysql.ArticleReview{}).Create(&review).Error
	return review, err
}

func ArticleHistory(id int, id2 int) (history mysql.ArticleHistory, err error) {
	history = mysql.ArticleHistory{
		UserId:    id,
		ArticleId: id2,
	}
	err = mysql.DB.Debug().Model(&mysql.ArticleHistory{}).Create(&history).Error
	return history, err
}

func ArticleGood(id int, id2 int) (good mysql.ArticleGood, err error) {
	good = mysql.ArticleGood{
		UserId:    id,
		ArticleId: id2,
	}
	err = mysql.DB.Debug().Model(&mysql.ArticleGood{}).Create(&good).Error
	return good, err
}
